load packages

library(pacman)
pacman::p_load(tidyverse, brms, ggeffects, kableExtra, tidybayes, install = TRUE)

define aesthetics

palette = c("#e64626", "#1985a1", "#4c5c68", "#FAC748")

plot_aes = theme_minimal() +
  theme(legend.position = "top",
        legend.text = element_text(size = 16),
        text = element_text(size = 18, family = "Futura Medium"),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        axis.text = element_text(color = "black"),
        axis.line = element_line(colour = "black"),
        axis.ticks.y = element_blank())

define functions

make_table = function(data) {
    data %>%
      broom.mixed::tidy(conf.int = TRUE) %>%
      filter(effect == "fixed") %>%
      mutate(term = gsub("\\(Intercept\\)", "intercept", term),
             term = gsub("regulation_expression", "signature expression", term),
             term = gsub("active_weekon", "intervention week (active)", term),
             term = gsub("active_weekoff", "intervention week (control)", term),
             term = gsub("signal_count", "signal", term),
             term = gsub(":", " x ", term),
             `b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", estimate, conf.low, conf.high)) %>%
      select(term, `b [95% CI]`) %>%
      knitr::kable(digits = 2)
}

load and tidy data

  • remove trials missing stimulus information
    • the following participants had technical errors during all mindful attention trials: sub-MURIP012, sub-MURIP063, sub-MURIP078
  • remove trials in which the mean signal intensity of the brain map is +/- 3 SDs from the mean

task data

task_data = read.csv("../data/task/cuereact_all062920.csv", stringsAsFactors = FALSE) %>%
  filter(grepl("rating", trial_type)) %>%
  select(pID, block_num, trial_num, trial_type, resp, rt, stim) %>%
  mutate(trial_cond = ifelse(grepl("friend3|friend4", trial_type), "regulation",
                      ifelse(grepl("friend1|friend2", trial_type), "up-regulation",
                      ifelse(grepl("mindful", trial_type), "regulation",
                      ifelse(grepl("nonalc", trial_type), "non-alcohol reactivity",
                      ifelse(grepl("rating_alc_react", trial_type), "reactivity", NA))))),
         trial_cond = factor(trial_cond, levels = c("non-alcohol reactivity", "reactivity", "regulation", "up-regulation"))) %>%
  rename("stimulus" = stim) %>%
  filter(!is.na(stimulus))

task_conditions = task_data %>%
  select(pID, trial_type) %>%
  unique() %>%
  filter(grepl("friend|mindful", trial_type) | pID %in% c("sub-MURIP012", "sub-MURIP063", "sub-MURIP078")) %>%
  mutate(condition = ifelse(grepl("friend", trial_type), "perspective", "mindful attention")) %>%
  select(-trial_type) %>%
  unique()

task_data_all = task_data %>%
  left_join(., task_conditions) %>%
  mutate(condition = ifelse(is.na(condition), "control", condition),
         trial_cond = factor(trial_cond, c("non-alcohol reactivity", "reactivity", "regulation", "up-regulation")))

task_mindful = task_data_all %>%
  filter(condition == "mindful attention")

signature expression data

file_dir = "../data/dots"
file_pattern = "sub.*"
file_list = list.files(file_dir, pattern = file_pattern)

dots_tmp = data.frame()

for (file in file_list) {
  tmp = tryCatch(read.table(file.path(file_dir,file), fill = TRUE, header = TRUE, sep = ",") %>%
                    extract(file, c("pID", "beta"), ".*(sub-MURIC[0-9]{3}|sub-MURIP[0-9]{3})/(beta_[0-9]{4}).nii") %>%
                    mutate(stimulus = as.character(stimulus)), error = function(e) message(file))
  
  dots_tmp = rbind(dots_tmp, tmp)
  rm(tmp)
}

dots = dots_tmp %>%
  left_join(., task_conditions) %>%
  mutate(condition = ifelse(is.na(condition), "control", condition)) %>%
  group_by(pID) %>%
  filter(!stimulus == "nan") %>%
  mutate(sd3_signal = 3 * sd(mean_signal, na.rm = TRUE),
         grand_mean_signal = mean(mean_signal, na.rm = TRUE),
         outlier = ifelse(mean_signal > grand_mean_signal + sd3_signal, 1,
                   ifelse(mean_signal < grand_mean_signal - sd3_signal, 1, 0))) %>%
  select(-sd3_signal, -grand_mean_signal) %>%
  filter(!outlier == 1)

EMA data

ema = read.csv("../data/ema/cleaned_EMA.csv", stringsAsFactors = FALSE) %>%
  select(pID, groupID, Condition, contains("signal"), Session.Name, active_week, drinks_number, contains("Craving"), gender_f, NumberResponses, SocialWeekend, amount_self_c, freq_self_c, contains("React")) %>%
  mutate(craving_previous = lag(Craving_Alc),
         Condition = gsub("mindful", "mindful attention", Condition),
         pID = gsub("muric", "sub-MURIC", pID),
         pID = gsub("muri", "sub-MURIP", pID),
         active_week = gsub("active", "on", active_week),
         active_week = gsub("control", "off", active_week),
         time_of_day = ifelse(grepl("Morning", Session.Name), "morning",
                       ifelse(grepl("Evening", Session.Name), "evening", NA))) %>%
  rename("condition" = Condition) 

merge and prep for modeling

merged = task_data_all %>%
  full_join(., dots) %>%
  filter(!pID == "sub-MURIC303") %>%
  filter(trial_cond %in% c("reactivity", "regulation")) %>%
  mutate(trial_cond_recode = ifelse(trial_cond == "regulation", .5, -.5),
         trial_cond = as.factor(as.character(trial_cond)))

between = merged %>%
  select(pID, dot, trial_cond, trial_cond_recode, condition) %>%
  group_by(pID, trial_cond, trial_cond_recode, condition) %>%
  summarize(dot_between = mean(dot, na.rm = TRUE)) %>%
  group_by(trial_cond, condition) %>%
  mutate(dot_between_c = scale(dot_between, scale = FALSE, center = TRUE)) %>%
  mutate(sd_dot = sd(dot_between, na.rm = TRUE),
         dot_between_std = dot_between_c / sd_dot) %>%
  select(-sd_dot)

reg_react_expression = between %>%
  select(pID, condition, trial_cond, dot_between_std) %>%
  unique() %>%
  mutate(trial_cond = sprintf("%s_expression", trial_cond)) %>%
  spread(trial_cond, dot_between_std)

ratings = read.csv("../data/task/post_scan_ratings.csv", stringsAsFactors = FALSE) %>%
  select(DistributionChannel, pID, mindful2) %>%
  filter(DistributionChannel == "anonymous" & grepl("muri|MURI", pID)) %>%
  extract(pID, c("pID", "number"), "(.*)([0-9]{3})") %>%
  mutate(pID = ifelse(pID %in% c("muri", "MURI"), "MURIP", pID),
         pID = sprintf("sub-%s%s", toupper(pID), number),
         confidence_rating = scale(as.numeric(mindful2), center = TRUE, scale = TRUE)) %>%
  select(-number, -mindful2, -DistributionChannel)

ema_within_intervention = ema %>%
  left_join(., reg_react_expression) %>%
  filter(!condition == "control") %>%
  group_by(pID) %>%
  mutate(drinks_number = scale(drinks_number, center = TRUE, scale = FALSE),
         Alc_React_Mindful = scale(Alc_React_Mindful, center = TRUE, scale = FALSE),
         Alc_React_Perspective = scale(Alc_React_Perspective, center = TRUE, scale = FALSE),
         mindful_scale = scale(Alc_React_Mindful, center = TRUE, scale = TRUE),
         perspective_scale = scale(Alc_React_Perspective, center = TRUE, scale = TRUE),
         response_scale = ifelse(condition == "mindful attention", mindful_scale, perspective_scale),
         craving_previous = scale(craving_previous, center = TRUE, scale = TRUE),
         craving_scale = scale(Craving_Alc, center = TRUE, scale = TRUE))

ema_within = ema_within_intervention %>%
  filter(condition == "mindful attention") %>%
  left_join(., ratings)

visualize raw data

intervention week effects

ema_within %>%
  select(pID, drinks_number, mindful_scale, craving_scale, active_week) %>%
  gather(key, value, -pID, -active_week) %>%
  ggplot(aes(active_week, value)) +
  stat_summary(aes(group = interaction(pID, key)), fun = "mean", geom = "line", color = "grey", size = .2) +
  stat_summary(aes(group = key), fun = "mean", geom = "line") +
  stat_summary(fun.data = "mean_cl_boot") +
  facet_grid(~key) +
  plot_aes +
  theme(legend.position = "none")

correlations

mindful responses & drinking

Association between how mindful you were when you encountered alcohol and how much you drank (morning signal = reported evening drinking, evening signal = reporting morning/afternoon drinking)

ema_within %>%
  ggplot(aes(mindful_scale, drinks_number, color = active_week, fill = active_week)) +
  geom_point(size = .5, alpha = .4) +
  geom_smooth(aes(group = interaction(pID, active_week)), method = "lm", se = FALSE, size = .2) +
  geom_smooth(method = "lm", alpha = .2) +
  scale_color_manual(values = palette) +
  scale_fill_manual(values = palette) +
  plot_aes

craving (lagged) & drinking

E.g. association between morning craving and morning/afternoon drinking reported in the evening

ema_within %>%
  ggplot(aes(craving_previous, drinks_number, color = active_week, fill = active_week)) +
  geom_point(size = .5, alpha = .4) +
  geom_smooth(aes(group = interaction(pID, active_week)), method = "lm", se = FALSE, size = .2) +
  geom_smooth(method = "lm", alpha = .2) +
  scale_color_manual(values = palette) +
  scale_fill_manual(values = palette) +
  plot_aes

craving (lagged) & responses

E.g. association between morning craving and morning/afternoon mindful responses to alcohol reported in the evening

ema_within %>%
  ggplot(aes(craving_previous, mindful_scale, color = active_week, fill = active_week)) +
  geom_point(size = .5, alpha = .4) +
  geom_smooth(aes(group = interaction(pID, active_week)), method = "lm", se = FALSE, size = .2) +
  geom_smooth(method = "lm", alpha = .2) +
  scale_color_manual(values = palette) +
  scale_fill_manual(values = palette) +
  plot_aes

responses & craving

E.g. association between morning/afternoon mindful responses to alcohol reported in the evening and craving reported in the evening

ema_within %>%
  ggplot(aes(mindful_scale, craving_scale, color = active_week, fill = active_week)) +
  geom_point(size = .5, alpha = .4) +
  geom_smooth(aes(group = interaction(pID, active_week)), method = "lm", se = FALSE, size = .2) +
  geom_smooth(method = "lm", alpha = .2) +
  scale_color_manual(values = palette) +
  scale_fill_manual(values = palette) +
  plot_aes

exploratory analyses

prior = c(prior(normal(0, 1), class=b))

mindful responses ~ active_week * regulation_expression

Do participants reporter more mindful responses (compared to their average) on active compared to control weeks?

Is this relationships stronger for participants who more strongly express the mindful attention signature?

plot

regression

vals = seq(-2, 2, .2)
predicted = ggeffects::ggpredict(response_week, c("regulation_expression [vals]",  "active_week")) %>%
  data.frame()

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_color_manual(name = "intervention week", values = palette) +
  scale_fill_manual(name = "intervention week", values = palette) +
  labs(y = "within-person mindful response rating (SD)\n", x = "\nsignature expression on mindful attention trials (SD)") +
  plot_aes +
  theme(legend.position = "top")

point range

predicted = ggeffects::ggpredict(response_week, c("regulation_expression [0, 1]", "active_week")) %>%
  data.frame() %>%
   mutate(x = ifelse(x == 1, "+1 SD", "mean"),
          x = factor(x, levels = c("mean", "+1 SD")),
          group = recode(group, "on" = "active", "off" = "control"),
          group = factor(group, levels = c("control", "active")))

predicted %>%
  ggplot(aes(group, predicted, color = x, group = x)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.05), size = 1.5) +
  geom_line(position = position_dodge(0.05), size = 1.5) +
  scale_color_manual(name = "mindful attention signature expression", values = palette) +
  scale_x_discrete(expand = c(.1, .1)) +
  coord_cartesian(ylim = c(-.5, .65)) +
  labs(y = "within-person mindful response rating (SD)\n", x = "\nintervention week") +
  plot_aes +
  theme(legend.position = "top")

summary

make_table(response_week)
term b [95% CI]
intercept -0.49 [-0.72, -0.27]
intervention week (active) 0.44 [0.18, 0.68]
signature expression -0.10 [-0.26, 0.06]
signal 0.01 [0.00, 0.02]
intervention week (active) x signature expression 0.29 [0.04, 0.52]

simple slopes

hypothesis(response_week,
           c(expression_mean = "active_weekon = 0",
             expression_1sd = "active_weekon + active_weekon:regulation_expression = 0"))$hypothesis %>%
  mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", Estimate, CI.Lower, CI.Upper)) %>%
  select(Hypothesis, `b [95% CI]`) %>%
  knitr::kable()
Hypothesis b [95% CI]
expression_mean 0.44 [0.18, 0.68]
expression_1sd 0.73 [0.38, 1.04]

craving ~ active_week * regulation_expression

Do participants reporter weaker cravings (compared to their average) on active compared to control weeks?

Is this relationships stronger for participants who more strongly express the mindful attention signature?

plot

regression

vals = seq(-2, 2, .2)
predicted = ggeffects::ggpredict(craving_week, c("regulation_expression [vals]",  "active_week")) %>%
  data.frame()

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_color_manual(name = "intervention week", values = palette) +
  scale_fill_manual(name = "intervention week", values = palette) +
  labs(y = "within-person craving rating (SD)\n", x = "\nsignature expression on mindful attention trials (SD)") +
  plot_aes +
  theme(legend.position = "top")

point range

predicted = ggeffects::ggpredict(craving_week, c("regulation_expression [0, 1]", "active_week")) %>%
  data.frame() %>%
   mutate(x = ifelse(x == 1, "+1 SD", "mean"),
          x = factor(x, levels = c("mean", "+1 SD")),
          group = recode(group, "on" = "active", "off" = "control"),
          group = factor(group, levels = c("control", "active")))

predicted %>%
  ggplot(aes(group, predicted, color = x, group = x)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.05), size = 1.5) +
  geom_line(position = position_dodge(0.05), size = 1.5) +
  scale_color_manual(name = "mindful attention signature expression", values = palette) +
  scale_x_discrete(expand = c(.1, .1)) +
  coord_cartesian(ylim = c(-.5, .65)) +
  labs(y = "within-person craving rating (SD)\n", x = "\nintervention week") +
  plot_aes +
  theme(legend.position = "top")

summary

make_table(craving_week)
term b [95% CI]
intercept -0.10 [-0.20, 0.01]
intervention week (active) 0.03 [-0.07, 0.13]
signature expression 0.03 [-0.04, 0.10]
signal 0.00 [-0.00, 0.01]
intervention week (active) x signature expression -0.06 [-0.17, 0.04]

simple slopes

hypothesis(craving_week,
           c(expression_mean = "active_weekon = 0",
             expression_1sd = "active_weekon + active_weekon:regulation_expression = 0"))$hypothesis %>%
  mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", Estimate, CI.Lower, CI.Upper)) %>%
  select(Hypothesis, `b [95% CI]`) %>%
  knitr::kable()
Hypothesis b [95% CI]
expression_mean 0.03 [-0.07, 0.13]
expression_1sd -0.03 [-0.18, 0.11]

drinking ~ active_week * regulation_expression

Do participants reporter drinking less (compared to their average) on active compared to control weeks?

Is this relationships stronger for participants who more strongly express the mindful attention signature?

plot

regression

vals = seq(-2, 2, .2)
predicted = ggeffects::ggpredict(drinking_week, c("regulation_expression [vals]",  "active_week")) %>%
  data.frame()

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_color_manual(name = "intervention week", values = palette) +
  scale_fill_manual(name = "intervention week", values = palette) +
  labs(y = "within-person number of drinks\n", x = "\nsignature expression on mindful attention trials (SD)") +
  plot_aes + 
  theme(legend.position = "top")

point range

predicted = ggeffects::ggpredict(drinking_week, c("regulation_expression [0, 1]", "active_week")) %>%
  data.frame() %>%
   mutate(x = ifelse(x == 1, "+1 SD", "mean"),
          x = factor(x, levels = c("mean", "+1 SD")),
          group = recode(group, "on" = "active", "off" = "control"),
          group = factor(group, levels = c("control", "active")))

predicted %>%
  ggplot(aes(group, predicted, color = x, group = x)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.05), size = 1.5) +
  geom_line(position = position_dodge(0.05), size = 1.5) +
  scale_color_manual(name = "mindful attention signature expression", values = palette) +
  scale_x_discrete(expand = c(.1, .1)) +
  coord_cartesian(ylim = c(-.3, .3)) +
  labs(y = "within-person number of drinks\n", x = "\nintervention week") +
  plot_aes +
  theme(legend.position = "top")

summary

make_table(drinking_week)
term b [95% CI]
intercept 0.20 [0.05, 0.35]
intervention week (active) -0.06 [-0.22, 0.08]
signature expression 0.11 [0.02, 0.21]
signal -0.01 [-0.01, -0.00]
intervention week (active) x signature expression -0.23 [-0.38, -0.08]

simple slopes

hypothesis(drinking_week,
           c(expression_mean = "active_weekon = 0",
             expression_1sd = "active_weekon + active_weekon:regulation_expression = 0"))$hypothesis %>%
  mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", Estimate, CI.Lower, CI.Upper)) %>%
  select(Hypothesis, `b [95% CI]`) %>%
  knitr::kable()
Hypothesis b [95% CI]
expression_mean -0.06 [-0.22, 0.08]
expression_1sd -0.29 [-0.50, -0.08]

drinking ~ mindful responses * regulation_expression

Do participants reporter drinking less (compared to their average) on active compared to control weeks?

Is this relationships stronger for participants who more strongly express the mindful attention signature?

plot

regression

vals = seq(-2, 2, .2)
predicted = ggeffects::ggpredict(drinking_mindful, c("mindful_scale [vals]", "regulation_expression [0, 1]")) %>%
  data.frame() %>%
  mutate(group = ifelse(group == 1, "+1 SD", "mean"),
         group = factor(group, levels = c("mean", "+1 SD")),)

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_color_manual(name = "intervention week", values = palette) +
  scale_fill_manual(name = "intervention week", values = palette) +
  labs(y = "within-person number of drinks\n", x = "\nwithin-person mindful response rating (SD)") +
  plot_aes + 
  theme(legend.position = "top")

summary

make_table(drinking_mindful)
term b [95% CI]
intercept 1.34 [0.90, 1.80]
mindful_scale -0.57 [-0.96, -0.14]
signature expression -0.27 [-0.50, -0.05]
signal -0.00 [-0.02, 0.02]
mindful_scale x signature expression -0.32 [-0.72, 0.08]

simple slopes

hypothesis(drinking_mindful,
           c(expression_mean = "mindful_scale = 0",
             expression_1sd = "mindful_scale + mindful_scale:regulation_expression = 0"))$hypothesis %>%
  mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", Estimate, CI.Lower, CI.Upper)) %>%
  select(Hypothesis, `b [95% CI]`) %>%
  knitr::kable()
Hypothesis b [95% CI]
expression_mean -0.57 [-0.96, -0.14]
expression_1sd -0.88 [-1.43, -0.35]

mediation

prior = c(prior(normal(0, 1), class=b))

mindful responses: no moderation

fit_brm %>%
  broom.mixed::tidy(conf.int = TRUE) %>%
  filter(effect == "fixed") %>%
  mutate(term = gsub("\\(Intercept\\)", "intercept", term),
         term = gsub("regulation_expression", "signature expression", term),
         term = gsub("active_weekon", "intervention week (active)", term),
         term = gsub("active_weekoff", "intervention week (control)", term),
         term = gsub("mindful_scale", "mindful response", term),
         response = gsub("mindfulscale", "mindful response", response),
         response = gsub("drinksnumber", "number of drinks", response),
         term = gsub(":", " x ", term),
         `b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", estimate, conf.low, conf.high)) %>%
  rename("outcome" = response) %>%
  select(outcome, term, `b [95% CI]`) %>%
  arrange(outcome) %>%
  knitr::kable(digits = 2)
outcome term b [95% CI]
mindful response intercept -0.24 [-0.39, -0.09]
mindful response intervention week (active) 0.50 [0.26, 0.73]
number of drinks intercept 1.33 [0.94, 1.74]
number of drinks intervention week (active) -0.02 [-0.56, 0.52]
number of drinks mindful response -0.59 [-0.93, -0.20]
hypothesis(
  fit_brm,
  'b_drinksnumber_mindful_scale * b_mindfulscale_active_weekon + cor_pID__mindfulscale_active_weekon__drinksnumber_active_weekon * sd_pID__mindfulscale_active_weekon * sd_pID__drinksnumber_mindful_scale = 0',
  class = NULL,
  seed  =  6523
)
## Hypothesis Tests for class :
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
## 1 (b_drinksnumber_m... = 0    -0.29      0.14    -0.56    -0.01         NA
##   Post.Prob Star
## 1        NA    *
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.

mindful responses: moderation

run model

#summary(fit_brm_m)
#prior_summary(fit_brm_m)

fit_brm_m %>%
  broom.mixed::tidy(conf.int = TRUE) %>%
  filter(effect == "fixed") %>%
  mutate(term = gsub("\\(Intercept\\)", "intercept", term),
         term = gsub("regulation_expression", "signature expression", term),
         term = gsub("active_weekon", "intervention week (active)", term),
         term = gsub("active_weekoff", "intervention week (control)", term),
         term = gsub("mindful_scale", "mindful response", term),
         response = gsub("mindfulscale", "mindful response", response),
         response = gsub("drinksnumber", "number of drinks", response),
         term = gsub(":", " x ", term),
         `b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", estimate, conf.low, conf.high)) %>%
  rename("outcome" = response) %>%
  select(outcome, term, `b [95% CI]`) %>%
  arrange(outcome) %>%
  knitr::kable(digits = 2, format = "pandoc")
outcome term b [95% CI]
mindful response intercept -0.21 [-0.38, -0.05]
mindful response intervention week (active) 0.49 [0.26, 0.71]
mindful response signature expression -0.15 [-0.29, 0.00]
mindful response intervention week (active) x signature expression 0.42 [0.18, 0.62]
number of drinks intercept 1.30 [0.93, 1.71]
number of drinks intervention week (active) 0.12 [-0.48, 0.70]
number of drinks signature expression -0.30 [-0.58, -0.03]
number of drinks mindful response -0.59 [-0.97, -0.18]
number of drinks signature expression x mindful response -0.30 [-0.69, 0.05]
hypothesis(
  fit_brm_m,
  'b_drinksnumber_mindful_scale * b_mindfulscale_active_weekon + cor_pID__mindfulscale_active_weekon__drinksnumber_active_weekon * sd_pID__mindfulscale_active_weekon * sd_pID__drinksnumber_mindful_scale = 0',
  class = NULL,
  seed  =  6523
)
## Hypothesis Tests for class :
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
## 1 (b_drinksnumber_m... = 0    -0.26      0.13    -0.53    -0.03         NA
##   Post.Prob Star
## 1        NA    *
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.

plots

mindful responses by intervention week

slopes_within = ema_within %>%
  select(pID, active_week, mindful_scale) %>%
  rename("x" = active_week,
         "predicted" = mindful_scale) %>%
  mutate(x = recode(x, "on" = "active", "off" = "control"),
         x = factor(x, levels = c("control", "active"))) %>%
  group_by(pID, x) %>%
  summarize(predicted = mean(predicted, na.rm = TRUE))
  
predicted = ggeffects::ggpredict(fit_brm_m, terms = c("active_week", "regulation_expression [0, 1]")) %>%
  data.frame() %>%
  mutate(x = recode(x, "on" = "active", "off" = "control"),
         group = recode(group, "0" = "mean", "1" = "+1 SD"),
         x = factor(x, levels = c("control", "active")))

(plot_response = predicted %>%
  filter(response.level == "mindfulscale") %>%
  ggplot(aes(x, predicted)) +
  geom_line(data = slopes_within, aes(x, predicted, group = pID), alpha = .3) +
  geom_line(aes(group = group, color = group), size = 2, , position = position_dodge(.1)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high, color = group), size = 2, position = position_dodge(.1)) +
  scale_x_discrete(expand = c(.1, .1)) +
  scale_color_manual(values = palette, name = "signature expression") +
  labs(x = "\nintervention week", y = "within-person mindful response (SD)\n") +
  plot_aes)

alchol consumption ~ mindful responses

vals = seq(-2,2,.2)

points_within = ema_within %>%
  select(pID, drinks_number, mindful_scale) %>%
  rename("x" = mindful_scale,
         "predicted" = drinks_number)

predicted = ggeffects::ggpredict(fit_brm_m, terms = c("mindful_scale", "regulation_expression [0, 1]")) %>%
  data.frame() %>%
  mutate(group = recode(group, "0" = "mean", "1" = "+1 SD"))

(plot_alcohol = predicted %>%
  filter(response.level == "drinksnumber") %>%
  ggplot(aes(x, predicted)) +
  geom_point(data = points_within, alpha = .2, size = 2, position = position_jitter(.1,.1)) +
  geom_line(aes(group = group, color = group), size = 2) +
  geom_ribbon(aes(fill = group, ymin = conf.low, ymax = conf.high), size = 2, alpha = .4) +
  scale_color_manual(values = palette, name = "signature expression") +
  scale_fill_manual(values = palette, name = "signature expression") +
  labs(x = "\nwithin-person mindful response (SD)", y = "number of drinks\n") +
  plot_aes)

combined

ggpubr::ggarrange(plot_response, plot_alcohol, nrow = 1, common.legend = TRUE)

craving: no moderation

summary(fit_brm_c)
##  Family: MV(gaussian, gaussian) 
##   Links: mu = identity; sigma = identity
##          mu = identity; sigma = identity 
## Formula: craving_previous ~ active_week + (0 + active_week | i | pID) 
##          drinks_number ~ active_week + craving_previous + (0 + active_week + craving_previous | i | pID) 
##    Data: ema_within (Number of observations: 1740) 
##   Draws: 4 chains, each with iter = 500; warmup = 250; thin = 4;
##          total post-warmup draws = 250
## 
## Group-Level Effects: 
## ~pID (Number of levels: 37) 
##                                                                   Estimate
## sd(cravingprevious_active_weekoff)                                    0.05
## sd(cravingprevious_active_weekon)                                     0.05
## sd(drinksnumber_active_weekoff)                                       0.11
## sd(drinksnumber_active_weekon)                                        0.11
## sd(drinksnumber_craving_previous)                                     0.31
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)    -0.17
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)      -0.06
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)        0.01
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)        0.04
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)        -0.02
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)          -0.40
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)    -0.20
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)      0.18
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)        0.06
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)        -0.09
##                                                                   Est.Error
## sd(cravingprevious_active_weekoff)                                     0.04
## sd(cravingprevious_active_weekon)                                      0.04
## sd(drinksnumber_active_weekoff)                                        0.06
## sd(drinksnumber_active_weekon)                                         0.06
## sd(drinksnumber_craving_previous)                                      0.05
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)      0.41
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)        0.40
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)         0.39
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)         0.40
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)          0.39
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)            0.41
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)      0.37
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)       0.38
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)         0.33
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)          0.34
##                                                                   l-95% CI
## sd(cravingprevious_active_weekoff)                                    0.00
## sd(cravingprevious_active_weekon)                                     0.00
## sd(drinksnumber_active_weekoff)                                       0.01
## sd(drinksnumber_active_weekon)                                        0.01
## sd(drinksnumber_craving_previous)                                     0.22
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)    -0.86
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)      -0.77
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)       -0.74
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)       -0.71
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)        -0.74
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)          -0.93
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)    -0.82
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)     -0.58
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)       -0.59
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)        -0.68
##                                                                   u-95% CI Rhat
## sd(cravingprevious_active_weekoff)                                    0.14 1.00
## sd(cravingprevious_active_weekon)                                     0.14 1.00
## sd(drinksnumber_active_weekoff)                                       0.23 1.01
## sd(drinksnumber_active_weekon)                                        0.24 1.00
## sd(drinksnumber_craving_previous)                                     0.43 1.00
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)     0.69 1.00
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)       0.73 1.00
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)        0.74 1.00
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)        0.74 1.00
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)         0.70 1.00
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)           0.58 1.00
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)     0.57 1.01
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)      0.81 1.00
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)        0.65 1.01
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)         0.59 1.00
##                                                                   Bulk_ESS
## sd(cravingprevious_active_weekoff)                                     834
## sd(cravingprevious_active_weekon)                                      951
## sd(drinksnumber_active_weekoff)                                        722
## sd(drinksnumber_active_weekon)                                         738
## sd(drinksnumber_craving_previous)                                      982
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)      833
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)        819
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)         876
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)        1022
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)          939
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)            807
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)      376
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)       412
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)         723
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)          729
##                                                                   Tail_ESS
## sd(cravingprevious_active_weekoff)                                     861
## sd(cravingprevious_active_weekon)                                      905
## sd(drinksnumber_active_weekoff)                                        915
## sd(drinksnumber_active_weekon)                                         866
## sd(drinksnumber_craving_previous)                                      821
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)      784
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)        970
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)         951
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)         980
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)          950
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)            794
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)      642
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)       531
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)         787
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)          823
## 
## Population-Level Effects: 
##                               Estimate Est.Error l-95% CI u-95% CI Rhat
## cravingprevious_Intercept        -0.01      0.03    -0.08     0.06 1.00
## drinksnumber_Intercept            0.07      0.05    -0.02     0.16 1.00
## cravingprevious_active_weekon     0.03      0.05    -0.07     0.13 1.00
## drinksnumber_active_weekon       -0.16      0.07    -0.30    -0.01 1.00
## drinksnumber_craving_previous     0.30      0.06     0.18     0.42 1.00
##                               Bulk_ESS Tail_ESS
## cravingprevious_Intercept         1013     1038
## drinksnumber_Intercept            1053      738
## cravingprevious_active_weekon     1143      979
## drinksnumber_active_weekon        1014      883
## drinksnumber_craving_previous      879      938
## 
## Family Specific Parameters: 
##                       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## sigma_cravingprevious     1.00      0.02     0.97     1.03 1.00      952
## sigma_drinksnumber        1.26      0.02     1.22     1.31 1.00      799
##                       Tail_ESS
## sigma_cravingprevious      881
## sigma_drinksnumber         933
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
fit_brm_c %>%
  broom.mixed::tidy(conf.int = TRUE) %>%
  filter(effect == "fixed") %>%
  mutate(term = gsub("\\(Intercept\\)", "intercept", term),
         term = gsub("regulation_expression", "signature expression", term),
         term = gsub("active_weekon", "intervention week (active)", term),
         term = gsub("active_weekoff", "intervention week (control)", term),
         term = gsub("craving_previous", "craving rating", term),
         response = gsub("cravingprevious", "craving rating", response),
         response = gsub("drinksnumber", "number of drinks", response),
         term = gsub(":", " x ", term),
         `b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", estimate, conf.low, conf.high)) %>%
  rename("outcome" = response) %>%
  select(outcome, term, `b [95% CI]`) %>%
  arrange(outcome) %>%
  knitr::kable(digits = 2)
outcome term b [95% CI]
craving rating intercept -0.01 [-0.08, 0.06]
craving rating intervention week (active) 0.03 [-0.07, 0.13]
number of drinks intercept 0.07 [-0.02, 0.16]
number of drinks intervention week (active) -0.16 [-0.30, -0.01]
number of drinks craving rating 0.30 [0.18, 0.42]
hypothesis(
  fit_brm_c,
  'b_drinksnumber_craving_previous * b_cravingprevious_active_weekon + cor_pID__cravingprevious_active_weekon__drinksnumber_active_weekon * sd_pID__cravingprevious_active_weekon * sd_pID__drinksnumber_craving_previous = 0',
  class = NULL,
  seed  =  6523
)
## Hypothesis Tests for class :
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
## 1 (b_drinksnumber_c... = 0     0.01      0.02    -0.03     0.05         NA
##   Post.Prob Star
## 1        NA     
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.

craving: moderation

summary(fit_brm_c)
##  Family: MV(gaussian, gaussian) 
##   Links: mu = identity; sigma = identity
##          mu = identity; sigma = identity 
## Formula: craving_previous ~ active_week * regulation_expression + (0 + active_week | i | pID) 
##          drinks_number ~ active_week + regulation_expression * craving_previous + (0 + active_week + craving_previous | i | pID) 
##    Data: ema_within (Number of observations: 1597) 
##   Draws: 4 chains, each with iter = 500; warmup = 250; thin = 4;
##          total post-warmup draws = 250
## 
## Group-Level Effects: 
## ~pID (Number of levels: 34) 
##                                                                   Estimate
## sd(cravingprevious_active_weekoff)                                    0.06
## sd(cravingprevious_active_weekon)                                     0.05
## sd(drinksnumber_active_weekoff)                                       0.12
## sd(drinksnumber_active_weekon)                                        0.11
## sd(drinksnumber_craving_previous)                                     0.30
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)    -0.17
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)      -0.01
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)       -0.00
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)       -0.02
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)         0.01
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)          -0.38
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)    -0.22
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)      0.17
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)       -0.09
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)         0.09
##                                                                   Est.Error
## sd(cravingprevious_active_weekoff)                                     0.04
## sd(cravingprevious_active_weekon)                                      0.04
## sd(drinksnumber_active_weekoff)                                        0.07
## sd(drinksnumber_active_weekon)                                         0.07
## sd(drinksnumber_craving_previous)                                      0.05
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)      0.41
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)        0.41
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)         0.41
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)         0.40
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)          0.40
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)            0.39
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)      0.38
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)       0.38
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)         0.35
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)          0.36
##                                                                   l-95% CI
## sd(cravingprevious_active_weekoff)                                    0.00
## sd(cravingprevious_active_weekon)                                     0.00
## sd(drinksnumber_active_weekoff)                                       0.01
## sd(drinksnumber_active_weekon)                                        0.01
## sd(drinksnumber_craving_previous)                                     0.21
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)    -0.83
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)      -0.75
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)       -0.74
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)       -0.73
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)        -0.71
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)          -0.92
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)    -0.83
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)     -0.60
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)       -0.72
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)        -0.62
##                                                                   u-95% CI Rhat
## sd(cravingprevious_active_weekoff)                                    0.16 1.00
## sd(cravingprevious_active_weekon)                                     0.15 1.00
## sd(drinksnumber_active_weekoff)                                       0.25 1.00
## sd(drinksnumber_active_weekon)                                        0.26 1.00
## sd(drinksnumber_craving_previous)                                     0.43 1.00
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)     0.68 1.00
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)       0.72 1.00
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)        0.76 1.00
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)        0.75 1.00
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)         0.74 1.00
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)           0.49 1.00
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)     0.58 1.01
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)      0.81 1.00
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)        0.63 1.00
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)         0.73 1.00
##                                                                   Bulk_ESS
## sd(cravingprevious_active_weekoff)                                     748
## sd(cravingprevious_active_weekon)                                      969
## sd(drinksnumber_active_weekoff)                                        809
## sd(drinksnumber_active_weekon)                                         908
## sd(drinksnumber_craving_previous)                                      976
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)     1010
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)        878
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)        1000
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)         898
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)          942
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)            837
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)      475
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)       646
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)         730
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)          714
##                                                                   Tail_ESS
## sd(cravingprevious_active_weekoff)                                     772
## sd(cravingprevious_active_weekon)                                      940
## sd(drinksnumber_active_weekoff)                                        913
## sd(drinksnumber_active_weekon)                                        1082
## sd(drinksnumber_craving_previous)                                      915
## cor(cravingprevious_active_weekoff,cravingprevious_active_weekon)      891
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekoff)        899
## cor(cravingprevious_active_weekon,drinksnumber_active_weekoff)         831
## cor(cravingprevious_active_weekoff,drinksnumber_active_weekon)         960
## cor(cravingprevious_active_weekon,drinksnumber_active_weekon)          617
## cor(drinksnumber_active_weekoff,drinksnumber_active_weekon)            991
## cor(cravingprevious_active_weekoff,drinksnumber_craving_previous)      704
## cor(cravingprevious_active_weekon,drinksnumber_craving_previous)       817
## cor(drinksnumber_active_weekoff,drinksnumber_craving_previous)         870
## cor(drinksnumber_active_weekon,drinksnumber_craving_previous)          867
## 
## Population-Level Effects: 
##                                                     Estimate Est.Error l-95% CI
## cravingprevious_Intercept                              -0.00      0.03    -0.07
## drinksnumber_Intercept                                  0.06      0.05    -0.04
## cravingprevious_active_weekon                           0.01      0.05    -0.09
## cravingprevious_regulation_expression                   0.02      0.04    -0.05
## cravingprevious_active_weekon:regulation_expression    -0.03      0.05    -0.14
## drinksnumber_active_weekon                             -0.14      0.07    -0.28
## drinksnumber_regulation_expression                     -0.00      0.04    -0.07
## drinksnumber_craving_previous                           0.29      0.06     0.18
## drinksnumber_regulation_expression:craving_previous     0.06      0.07    -0.08
##                                                     u-95% CI Rhat Bulk_ESS
## cravingprevious_Intercept                               0.07 1.00      958
## drinksnumber_Intercept                                  0.17 1.00      915
## cravingprevious_active_weekon                           0.12 1.00      915
## cravingprevious_regulation_expression                   0.10 1.00      820
## cravingprevious_active_weekon:regulation_expression     0.07 1.00     1001
## drinksnumber_active_weekon                              0.00 1.00      974
## drinksnumber_regulation_expression                      0.07 1.00      971
## drinksnumber_craving_previous                           0.41 1.00      997
## drinksnumber_regulation_expression:craving_previous     0.18 1.00      901
##                                                     Tail_ESS
## cravingprevious_Intercept                                948
## drinksnumber_Intercept                                  1042
## cravingprevious_active_weekon                            950
## cravingprevious_regulation_expression                    729
## cravingprevious_active_weekon:regulation_expression      883
## drinksnumber_active_weekon                               985
## drinksnumber_regulation_expression                       828
## drinksnumber_craving_previous                            897
## drinksnumber_regulation_expression:craving_previous     1037
## 
## Family Specific Parameters: 
##                       Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
## sigma_cravingprevious     1.00      0.02     0.97     1.04 1.00      978
## sigma_drinksnumber        1.27      0.02     1.22     1.31 1.00      993
##                       Tail_ESS
## sigma_cravingprevious      839
## sigma_drinksnumber         882
## 
## Draws were sampled using sampling(NUTS). For each parameter, Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the potential
## scale reduction factor on split chains (at convergence, Rhat = 1).
#prior_summary(fit_brm_m)

fit_brm_c %>%
  broom.mixed::tidy(conf.int = TRUE) %>%
  filter(effect == "fixed") %>%
  mutate(term = gsub("\\(Intercept\\)", "intercept", term),
         term = gsub("regulation_expression", "signature expression", term),
         term = gsub("active_weekon", "intervention week (active)", term),
         term = gsub("active_weekoff", "intervention week (control)", term),
         term = gsub("craving_previous", "craving rating", term),
         response = gsub("cravingprevious", "craving rating", response),
         response = gsub("drinksnumber", "number of drinks", response),
         term = gsub(":", " x ", term),
         `b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", estimate, conf.low, conf.high)) %>%
  rename("outcome" = response) %>%
  select(outcome, term, `b [95% CI]`) %>%
  arrange(outcome) %>%
  knitr::kable(digits = 2)
outcome term b [95% CI]
craving rating intercept -0.00 [-0.07, 0.07]
craving rating intervention week (active) 0.01 [-0.09, 0.12]
craving rating signature expression 0.02 [-0.05, 0.10]
craving rating intervention week (active) x signature expression -0.03 [-0.14, 0.07]
number of drinks intercept 0.06 [-0.04, 0.17]
number of drinks intervention week (active) -0.14 [-0.28, 0.00]
number of drinks signature expression -0.00 [-0.07, 0.07]
number of drinks craving rating 0.29 [0.18, 0.41]
number of drinks signature expression x craving rating 0.06 [-0.08, 0.18]
hypothesis(
  fit_brm_c,
  'b_drinksnumber_craving_previous * b_cravingprevious_active_weekon + cor_pID__cravingprevious_active_weekon__drinksnumber_active_weekon * sd_pID__cravingprevious_active_weekon * sd_pID__drinksnumber_craving_previous = 0',
  class = NULL,
  seed  =  6523
)
## Hypothesis Tests for class :
##                 Hypothesis Estimate Est.Error CI.Lower CI.Upper Evid.Ratio
## 1 (b_drinksnumber_c... = 0        0      0.02    -0.03     0.04         NA
##   Post.Prob Star
## 1        NA     
## ---
## 'CI': 90%-CI for one-sided and 95%-CI for two-sided hypotheses.
## '*': For one-sided hypotheses, the posterior probability exceeds 95%;
## for two-sided hypotheses, the value tested against lies outside the 95%-CI.
## Posterior probabilities of point hypotheses assume equal prior probabilities.

confidence ratings

mindful responses ~ active_week * confidence_rating

Do participants reporter more mindful responses (compared to their average) on active compared to control weeks?

Is this relationships stronger for participants who reported greater confidence with mindful attention?

plot

regression

vals = seq(-2, 2, .2)
predicted = ggeffects::ggpredict(response_week, c("confidence_rating [vals]",  "active_week")) %>%
  data.frame()

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_color_manual(name = "intervention week", values = palette) +
  scale_fill_manual(name = "intervention week", values = palette) +
  labs(y = "within-person mindful response rating (SD)\n", x = "\nconfidence rating (SD)") +
  plot_aes +
  theme(legend.position = "top")

point range

predicted = ggeffects::ggpredict(response_week, c("confidence_rating [0, 1]", "active_week")) %>%
  data.frame() %>%
   mutate(x = ifelse(x == 1, "+1 SD", "mean"),
          x = factor(x, levels = c("mean", "+1 SD")),
          group = recode(group, "on" = "active", "off" = "control"),
          group = factor(group, levels = c("control", "active")))

predicted %>%
  ggplot(aes(group, predicted, color = x, group = x)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.05), size = 1.5) +
  geom_line(position = position_dodge(0.05), size = 1.5) +
  scale_color_manual(name = "confidence rating", values = palette) +
  scale_x_discrete(expand = c(.1, .1)) +
  coord_cartesian(ylim = c(-.5, .65)) +
  labs(y = "within-person mindful response rating (SD)\n", x = "\nintervention week") +
  plot_aes +
  theme(legend.position = "top")

summary

make_table(response_week)
term b [95% CI]
intercept -0.53 [-0.76, -0.30]
intervention week (active) 0.45 [0.16, 0.72]
confidence_rating -0.02 [-0.20, 0.16]
signal 0.01 [0.01, 0.02]
intervention week (active) x confidence_rating 0.07 [-0.22, 0.36]

simple slopes

hypothesis(response_week,
           c(expression_mean = "active_weekon = 0",
             expression_1sd = "active_weekon + active_weekon:confidence_rating = 0"))$hypothesis %>%
  mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", Estimate, CI.Lower, CI.Upper)) %>%
  select(Hypothesis, `b [95% CI]`) %>%
  knitr::kable()
Hypothesis b [95% CI]
expression_mean 0.45 [0.16, 0.72]
expression_1sd 0.53 [0.12, 0.91]

craving ~ active_week * confidence_rating

Do participants reporter weaker cravings (compared to their average) on active compared to control weeks?

Is this relationships stronger for participants who reported greater confidence with mindful attention?

plot

regression

vals = seq(-2, 2, .2)
predicted = ggeffects::ggpredict(craving_week, c("confidence_rating [vals]",  "active_week")) %>%
  data.frame()

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_color_manual(name = "intervention week", values = palette) +
  scale_fill_manual(name = "intervention week", values = palette) +
  labs(y = "within-person craving rating (SD)\n", x = "\nconfidence rating (SD)") +
  plot_aes +
  theme(legend.position = "top")

point range

predicted = ggeffects::ggpredict(craving_week, c("confidence_rating [0, 1]", "active_week")) %>%
  data.frame() %>%
   mutate(x = ifelse(x == 1, "+1 SD", "mean"),
          x = factor(x, levels = c("mean", "+1 SD")),
          group = recode(group, "on" = "active", "off" = "control"),
          group = factor(group, levels = c("control", "active")))

predicted %>%
  ggplot(aes(group, predicted, color = x, group = x)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.05), size = 1.5) +
  geom_line(position = position_dodge(0.05), size = 1.5) +
  scale_color_manual(name = "confidence rating", values = palette) +
  scale_x_discrete(expand = c(.1, .1)) +
  coord_cartesian(ylim = c(-.5, .65)) +
  labs(y = "within-person craving rating (SD)\n", x = "\nintervention week") +
  plot_aes +
  theme(legend.position = "top")

summary

make_table(craving_week)
term b [95% CI]
intercept -0.07 [-0.18, 0.04]
intervention week (active) 0.01 [-0.08, 0.11]
confidence_rating -0.01 [-0.09, 0.06]
signal 0.00 [-0.00, 0.01]
intervention week (active) x confidence_rating 0.03 [-0.07, 0.13]

simple slopes

hypothesis(craving_week,
           c(expression_mean = "active_weekon = 0",
             expression_1sd = "active_weekon + active_weekon:confidence_rating = 0"))$hypothesis %>%
  mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", Estimate, CI.Lower, CI.Upper)) %>%
  select(Hypothesis, `b [95% CI]`) %>%
  knitr::kable()
Hypothesis b [95% CI]
expression_mean 0.01 [-0.08, 0.11]
expression_1sd 0.04 [-0.10, 0.19]

drinking ~ active_week * confidence_rating

Do participants reporter drinking less (compared to their average) on active compared to control weeks?

Is this relationships stronger for participants who reported greater confidence with mindful attention?

plot

regression

vals = seq(-2, 2, .2)
predicted = ggeffects::ggpredict(drinking_week, c("confidence_rating [vals]",  "active_week")) %>%
  data.frame()

predicted %>%
  ggplot(aes(x, predicted, color = group, fill = group)) +
  geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, color = NA) +
  geom_line(size = 1) +
  scale_color_manual(name = "intervention week", values = palette) +
  scale_fill_manual(name = "intervention week", values = palette) +
  labs(y = "within-person number of drinks\n", x = "\nconfidence rating (SD)") +
  plot_aes + 
  theme(legend.position = "top")

point range

predicted = ggeffects::ggpredict(drinking_week, c("confidence_rating [0, 1]", "active_week")) %>%
  data.frame() %>%
   mutate(x = ifelse(x == 1, "+1 SD", "mean"),
          x = factor(x, levels = c("mean", "+1 SD")),
          group = recode(group, "on" = "active", "off" = "control"),
          group = factor(group, levels = c("control", "active")))

predicted %>%
  ggplot(aes(group, predicted, color = x, group = x)) +
  geom_pointrange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.05), size = 1.5) +
  geom_line(position = position_dodge(0.05), size = 1.5) +
  scale_color_manual(name = "confidence rating", values = palette) +
  scale_x_discrete(expand = c(.1, .1)) +
  coord_cartesian(ylim = c(-.3, .3)) +
  labs(y = "within-person number of drinks\n", x = "\nintervention week") +
  plot_aes +
  theme(legend.position = "top")

summary

make_table(drinking_week)
term b [95% CI]
intercept 0.23 [0.08, 0.38]
intervention week (active) -0.10 [-0.25, 0.06]
confidence_rating 0.06 [-0.04, 0.16]
signal -0.01 [-0.01, -0.00]
intervention week (active) x confidence_rating -0.12 [-0.28, 0.03]

simple slopes

hypothesis(drinking_week,
           c(expression_mean = "active_weekon = 0",
             expression_1sd = "active_weekon + active_weekon:confidence_rating = 0"))$hypothesis %>%
  mutate(`b [95% CI]` = sprintf("%.2f [%.2f, %.2f]", Estimate, CI.Lower, CI.Upper)) %>%
  select(Hypothesis, `b [95% CI]`) %>%
  knitr::kable()
Hypothesis b [95% CI]
expression_mean -0.10 [-0.25, 0.06]
expression_1sd -0.22 [-0.44, 0.00]